using System;
using System.Text;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.UI.HtmlControls ;
using System.Web.Security ; 
namespace SystemFrameworks.Util
{
	/// <summary>
	/// Summary description for FormHelp.
	/// </summary>
	public class FormHelp
	{

		#region Private Const 

		// Invalid Status flag in database
		private const int	STATUS_INVALID					= -1;

		// Key name in Web.config
		private const string DOLLAR_FORMAT					= "DollarFormat";
		private const string DATE_FORMAT					= "DateFormat";
		private const string SPECIAL_UNIT					= "SpecialUnit";
		private const string COUNT_LEVEL_LIMIT				= "CountOfLevelLimit";
		private const string COUNT_APPROVE_LIMIT			= "CountOfApproveLimit";
		private const string REPORT_TEMP_PATH				= "ReportTempPath";
		private const string LOGIN_LIMIT					= "LoginLimit";
		private const string PASSWORD_EXPIRED_DAYS			= "PasswordExpiredDays";
		private const string COMMON_MAIL					= "CommonMailAddress";
		private const string CRQF_NUMBER_START_YEAR			= "CrqfNumberStartYear";
		private const string LOGIN_EXPIRED_DAYS				= "LoginExpiredDays";
		private const string PASSWORD_LOCK_DAYS				= "PasswordLockDays";
		private const string USER_LIST_SHOW					= "UserListShow";
		private const string SPECIAL_USER					= "SpecialUser";
		private const string UPPER_LIMIT_PROJECT			= "UpperLimitProject";
		private const string UPPER_LIMIT_ATTACH				= "UpperLimitAttach";
		

		private const string DEFAULT_DECIMAL				= "0.00";		
		private const string CRQFNUMBER_STANDARD_HEAD		= "yyyy-MM-";
		private const string STANDARD_DATA_FORMAT			= "MM/dd/yyyy";

		private const string CRQFNUMBER_REGULATION			= @"\d{4}-\d{2}-\d{3}";
		// For DropDownList
		private const string HEAD_SELECT_ALL				= "--Select All--";
		private const string BASE_TEXT_VALUE				= "FieldValue";
		private const string BASE_FIELD_VALUE				= "BaseId";

		// Class
		private const string CSS_TD_TITLE_SUP				= "tdPageTitle";
		private const string CSS_TD_TITLE_SUB				= "tdTitlChild";
		private const string CSS_VISIBLE					= "displayInline";
		private const string CSS_INVISIBLE					= "displayNone";

		#endregion

		#region Private Static Readonly

		private static readonly string	_DollarFormat				= string.Empty;		
		private static readonly string	_DateFormat					= string.Empty;		
		private static readonly string	_ReportTempPath				= string.Empty;	
		private static readonly string  _LoginLimit					= string.Empty;
		private static readonly string	_SpecialUnit				= string.Empty;
		private static readonly string	_CommonMail					= string.Empty;	
		private static readonly string  _SpecialUser				= string.Empty;		
		private static readonly int		_CountLevelLimit			= NullHelper.NullInt;
		private static readonly int		_CountApproveLimit			= NullHelper.NullInt;
		private static readonly int		_PasswordExpiredDays		= NullHelper.NullInt;
		private static readonly int		_CrqfNumberStartYear		= NullHelper.NullInt;
		private static readonly int		_LoginExpiredDays			= NullHelper.NullInt;
		private static readonly int		_PasswordLockDays			= NullHelper.NullInt;
		private static readonly int		_UpperLimitProject			= NullHelper.NullInt;
		private static readonly int		_UpperLimitAttach			= NullHelper.NullInt;
		private static readonly bool	_UserListShow				= false;			

		#endregion

		static FormHelp()
		{
			_DollarFormat		= ConfigurationSettings.AppSettings[ DOLLAR_FORMAT ];
			_DateFormat			= ConfigurationSettings.AppSettings[ DATE_FORMAT ];
			_SpecialUnit		= ConfigurationSettings.AppSettings[ SPECIAL_UNIT ];
			_ReportTempPath		= ConfigurationSettings.AppSettings[ REPORT_TEMP_PATH ];
			_CommonMail			= ConfigurationSettings.AppSettings[ COMMON_MAIL ];
			_LoginLimit			= ConfigurationSettings.AppSettings[ LOGIN_LIMIT ];
			_CountLevelLimit		= int.Parse( ConfigurationSettings.AppSettings[ COUNT_LEVEL_LIMIT ] );
			_CountApproveLimit		= int.Parse( ConfigurationSettings.AppSettings[ COUNT_APPROVE_LIMIT ] );
			_PasswordExpiredDays	= int.Parse( ConfigurationSettings.AppSettings[ PASSWORD_EXPIRED_DAYS] );
			_CrqfNumberStartYear	= int.Parse( ConfigurationSettings.AppSettings[ CRQF_NUMBER_START_YEAR ] );
			_LoginExpiredDays		= int.Parse( ConfigurationSettings.AppSettings[ LOGIN_EXPIRED_DAYS ] );
			_PasswordLockDays		= int.Parse( ConfigurationSettings.AppSettings[ PASSWORD_LOCK_DAYS] );
			_UpperLimitProject		= int.Parse( ConfigurationSettings.AppSettings[ UPPER_LIMIT_PROJECT] );
			_UpperLimitAttach		= int.Parse( ConfigurationSettings.AppSettings[ UPPER_LIMIT_ATTACH] );
			_UserListShow			= bool.Parse( ConfigurationSettings.AppSettings[ USER_LIST_SHOW ] );
			_SpecialUser			= ConfigurationSettings.AppSettings[ SPECIAL_USER ] ;
		}

		private FormHelp()
		{
		}

		#region Public Const String

		public const string  NEW_DATA="NEW";
		public const string  EDIT_DATA="EDIT";
		public const string  DELETE_DATA="DELETE";
		public const string  REFERENCE_DATA="REFERENCE";
		public const string  MAINTAIN_DATA="MAINTAIN";
		public const string  DRAFTS_DATA="DRAFTS";
		public const string  SUBMIT_DATA="SUBMIT";
		public const string  UPDATE_DATA="UPDATE";
		public const string	 CANCEL_DATA="CANCEL";
		public const string  APPROVE_DATA="APPROVE";
		public const string  REJECT_DATA="REJECT";

		// Command for Action
		public const string COMMAND_PAGE			= "PAGE";
		public const string COMMAND_GO_TO			= "GOTO";
		public const string COMMAND_GO_TO_REF		= "GOTOREF";
		public const string COMMAND_APPROVE			= "APPROVE";


		//to define  the type of service constant to get data from control system table
		public const string TYPE_OF_SERVICE				= "SERVICE";
		public const string APPROVE_TYPE				= "APPROVE_TYPE";
		public const string ACTION_NAME					= "ACTION_NAME";
		public const string BUDGETTED					= "BUDGETTED";
		public const string ADMIN_OPTION				= "ADMIN_OPTION";
		public const string STAFF_STATUS				= "STAFF_STATUS";

		public const string ON_OFF_SITE					= "ON_OFF_SITE";
		public const string EXPENSE_TYPE				= "EXPENSE_TYPE";
		public const string CRQF_FORM_STATUS			= "CRQF_FORM_STATUS";
		public const string ROLE_TYPE					= "ROLE_TYPE";
		public const string REASON_FOR_LEAVING          = "REASON_FOR_LEAVING";
		public const string CONTRACTOR_TYPE             = "CONTRACTOR_TYPE";
		public const string SEARCH_TYPE					= "SEARCH_TYPE";
		public const string RESOURCE_ACTION				= "RESOURCE_ACTION";
		public const string IS_PUBLISH					= "IS_PUBLISH";
		public const string REPORT_TYPE					= "REPORT_TYPE";

		// Page name
		public const string PAGE_CRQF_DRAFT					= "CrqfDraft.aspx";
		public const string PAGE_CRQF_BODYSHOP_PROJECT		= "CrqfBodyshopProject.aspx";
		public const string PAGE_CRQF_SUBMIT_VIEW			= "CrqfSubmitView.aspx";
		public const string PAGE_CRQF_PEND					= "CrqfPend.aspx";
		public const string PAGE_CRQF_FOR_ACTION			= "CrqfForAction.aspx";
		public const string PAGE_ERROR						= "";


		// Page name for Flow
		public const string PAGE_FLOW_BEGINNER				= "../CrqfForm/FlowBeginner.aspx";
		public const string PAGE_FLOW_JUNIOR				= "../CrqfForm/FlowJunior.aspx";
		public const string PAGE_FLOW_SENIOR				= "../CrqfForm/FlowSenior.aspx";
		public const string PAGE_FLOW_REGISTER				= "../CrqfForm/FlowRegister.aspx";
		public const string PAGE_FLOW_VIEW					= "../CrqfForm/FlowView.aspx";

		// View string
		public const string	TRANSFER_FROM					= "Transfer/ Renew<BR>(From {0})";
		public const string	TRANSFER_TO						= "Transfer/ Renew<BR>(To {0})";
		public const string	TRANSFER_FROM_TO				= "Transfer/ Renew<BR>(From {0} To {0})";

		public const string OVERLAP_TO						= ",<BR>Overlapping {0}";
		private const string OVERLAP_BY						= "Overlapped By {0}";
		public const string	OVERLAP_APPROVED				= OVERLAP_BY + ",<BR>Fincon Acknowledged";
		public const string OVERLAP_PENDING					= OVERLAP_BY + ",<BR>Pending Acknowledge";

		public const string	EXPIRED_CRQFNUMBER				= "{0}<BR>(Expired CRQF)";
		public const string	EXPIRED_STATUS					= "Expired";
		public const string	EXPIRED_ACTION_BY				= "System";


		
		//delegation moduleId 
		public const string DELEGATION_MODULE_ID			= "00000130";
		public const string DELEGATION_AUDITTRAIL_MODULE_ID = "00000230";
		public const string REQUESTOR_MODULE_ID			    = "00000001";

		//User Request
		public const string CHANGE_PASSWORD					= "CHANGE_PASSWORD";
		public const string UNLOCK							= "UNLOCK";
		#endregion
		
		#region Public Static Property

		#region Property	-- Format
		public static string ClientIp
		{
			get
			{
				return  System.Web.HttpContext.Current.Request.UserHostAddress;
			}
		}
		public static string CrqfNumberHeadFormat
		{
			get
			{
				return CRQFNUMBER_STANDARD_HEAD;
			}
		}
		public static string StandDataFormat
		{
			get
			{
				return STANDARD_DATA_FORMAT;
			}
		}
		

		public static string CrqfNumberRegulation
		{
			get
			{
				return CRQFNUMBER_REGULATION;
			}
		}

		public static string DateFormat
		{
			get
			{
				return _DateFormat;
			}
		}

		public static string DollarFormat
		{
			get
			{
				return _DollarFormat;
			}	
		}
		public static string ReportTempPath
		{
			get
			{
				return _ReportTempPath;
			}	
		}
		public static string LoginLimit
		{
			get
			{
				return _LoginLimit;
			}	
		}
		public static string CommonMail
		{
			get
			{
				return _CommonMail;
			}	
		}
		public static int PasswordExpiredDays
		{
			get
			{
				return _PasswordExpiredDays;
			}	
		}

		public static int LoginExpiredDays
		{
			get
			{
				return _LoginExpiredDays;
			}	
		}

		public static int PasswordLockDays		
		{
			get
			{
				return _PasswordLockDays;
			}	
		}
		public static bool UserListShow		
		{
			get
			{
				return _UserListShow;
			}	
		}
		public static string SpecialUser		
		{
			get
			{
				return _SpecialUser;
			}	
		}

		public static string DateLongFormat
		{
			get
			{
				return DateFormat + " HH:mm:ss";
			}
		}

		public static int CountLevelLimit
		{
			get
			{
				return _CountLevelLimit;
			}
		}

		public static int CountApproveLimit
		{
			get
			{
				return _CountApproveLimit;
			}
		}

		public static int CrqfNumberStartYear
		{
			get
			{
				return _CrqfNumberStartYear;
			}
		}

		/// <summary>
		/// Upper limit for catenating ProjectText queue 
		/// </summary>
		public static int UpperLimitProject
		{
			get
			{
				return _UpperLimitProject;
			}
		}

		/// <summary>
		/// Upper limit for catenating Attachment queue 
		/// </summary>
		public static int UpperLimitAttach
		{
			get
			{
				return _UpperLimitAttach;
			}
		}

		#endregion
		
		#region Property -- Class

		public static string CssTdTitleSup
		{
			get
			{
				return CSS_TD_TITLE_SUP;
			}
		}	

		public static string CssTdTitleSub
		{
			get
			{
				return CSS_TD_TITLE_SUB;
			}
		}	

		public static string CssVisible
		{
			get
			{
				return CSS_VISIBLE;
			}
		}	

		public static string CssInvisible
		{
			get
			{
				return CSS_INVISIBLE;
			}
		}

		#endregion

	
		public static string SpecialUnit
		{
			get
			{
				return _SpecialUnit;
			}
		}

		public static int StatusInvalid
		{
			get
			{
				return STATUS_INVALID;
			}
		}

		#endregion
		
		#region Enum Type
		
		/// <summary>
		/// Record status of database
		/// </summary>
		public enum RecordStatus
		{
			Valid = 0,
			Deleted = 1
		}

		/// <summary>
		/// Budgetted selelcted status - CrqfBodyshopProject.aspx 
		/// </summary>
		public enum Budgetted
		{
			Yes = 0,
			No = 1
		}

		/// <summary>
		/// OnOffSite selelcted status - CrqfBodyshopProject.aspx
		/// </summary>
		public enum OnOffSite
		{
			OnSite = 0,
			OffSite = 1
		}

		// TypeOfService selelcted status - CrqfBodyshopProject.aspx
		public enum TypeOfService
		{
			BodyShop		= 0,
			TimeMaterial	= 1,
			FixedPrice		= 2
		}

		// ApproveType selelcted status - CrqfBodyshopProject.aspx
		public enum ApproveType 
		{
			NewHire = 0,
			Renewal = 1
		}

		//  ExpenseType selelcted status - CrqfBodyshopProject.aspx
		public enum ExpenseType
		{
			Exp = 0,
			Cap = 1
		}
		public enum FunctionType
		{
			MainTain=0,
			Query=1,
			Apprival=2

		}
		public enum  FormControlStatus 
		{
			NEW_STATUS = 1,
			EDIT_STATUS = 2,
			DELETE_STATUS = 3,
			REFERENCE_STATUS = 4,
			APPROVE_STATUS =5,
			CANCEL_STATUS =6
		}

		//this enumeration is defined as a table Type to distinct the which table is selected
		public enum  enumTableType
		{
			Division=1,
			Region=2,
			Units=3,
			Location=4,
			Team=5,
			Project=6,
			CostCenter=7,
			Supervisor=8,
			Vendor = 9 ,
			ContractorRole = 10,
			AdditionalReason = 11
		}

		// Status of the values
		public enum  enumStatus
		{
			NEW=0,
			APPROVE=1,
			REJECT=2,
		}

		public enum  FormUserRight
		{
			REFERENCE_RIGHT = 1, 
			SEARCH_RIGHT=2,	
			NEW_RIGHT = 4,
			EDIT_RIGHT = 8,           			
			DELETE_RIGHT = 16,         
		}

		//to define the attachment type for the crqf form
		public enum AttachmentType
		{
			FUND_BY = 0,
			SKILLS_REQUIRE = 1,
			PURPOSE = 2,
			SOW = 3,
			SOW_EXTENSION = 4,
		}

		//to define Approve Status for StaffInfo
		public enum  ApproveStatus 
		{
			Pending = 0, //
			Approved = 1,
    		Rejected = 2,
			Deleted = 4,
			Locked = 5
		}

		// User Sub role
		public enum UserSubRole
		{
			Requestor = 0,
			TeamHeadOrDirector = 1,
			MdorDirector = 2,
			Fincon = 3,			
			AtoReviewer = 4,
			AtoHead = 5
		}

		// User  role
		public enum UserRole
		{
			UserRole = 10,
			ReportRole = 11,
			Administrator = 12,
			SystemAdministrator = 13,
			SpecialCsts = 14
		}

		// Delete Flag
		public enum DeleteFlag
		{
			EXISTS = 0,
			DELETED = 1	
		}

		
		// FieldType
		public enum FieldType
		{
			INT = 0,
			DATETIME = 1,
			DECIMAL = 2 ,
			VARCHAR = 3
		}
		
		// TableName
		public enum TableName
		{
			TBaseInfo = 0,
			TControlSystem = 1,
			TStaffInfo = 2,
			TCurrencyInfo = 3
		}
		// Control System
		public enum ControlSystem
		{
			SERVICE = 0,
			ADMIN_OPTION = 1,
			BUDGETTED = 2,
			ON_OFF_SITE = 3,
			EXPENSE_TYPE = 4,
			CRQF_FORM_STATUS = 5,
			APPROVE_TYPE =6,
			ROLE_TYPE = 7,
			REASON_FOR_LEAVING = 8,
			CONTRACTOR_TYPE=9
		}

		public enum CrqfStatus
		{
			Invalid			= -1,
			Draft			= 0,
			Submit			= 1,
			PendApprove		= 2,
			Return			= 3,
			Reject			= 4,
			Register		= 5,
			Archive			= 6,
			PendAcknowledge	= 9
		}

		/// <summary>
		/// Activity type for TActivityData
		/// </summary>
		public enum ActivityType
		{
			Submit			= 0,
			Modify			= 1,
			Approve			= 2,
			Return			= 3,
			Reject			= 4,
			Disregard		= 5,
			ApproveOverlap	= 6,
			Revise			= 7,			// For Project
			SubmitExtension	= 8,			// For Project
			Acknowledge		= 9				// For Project
		}

		/// <summary>
		/// Activity category for TActivityInfo
		/// </summary>
		public enum ActivityCategory
		{
			Common		= 0,			// For BodyShop and Project
			Acknowledge	= 1				// Only For Project to Acknowledge
		}

		/// <summary>
		/// AduitTrail show Attachment detail or trail detail
		/// </summary>
		public enum AttachmentTrailStatus
		{
			Attachment = 0,
			Trail = 1
		}
		/// <summary>
		/// delegation Status
		/// </summary>
		public enum DelegationStatus
		{
			Delegation = 0,
			UnDelegation = 1
		}
		/// <summary>
		/// delegation Role
		/// </summary>
		public enum DelegationRole
		{
			MdDirectors = 0,
			DelegationTo = 1
		}
		/// <summary>
		/// Role Type  
		/// </summary>
		public enum RoleType
		{
			Supervisor = 0
		}
		/// <summary>
		/// Contractor Type 
		/// </summary>
		public enum ContractorType
		{
			R = 0,
			S= 1
		}
		/// <summary>
		/// Resource Action
		/// </summary>
		public enum ResourceAction
		{
			OVERLAPPING = 0,
			TERMINATE = 1,
			TRANSFERRENEW = 2,
			DELETE = 3,
			NEW = 4,
			SAVE = 5
		}
		/// <summary>
		/// Resource Action Status
		/// </summary>
		public enum ResourceStatus
		{
			OVERLAPPING = 0,
			TERMINATE = 1,
			TRANSFER = 2,
			DELETE = 3,
			NEW = 4,
			SAVE = 5,
			RENEW = 6
		}
		/// <summary>
		/// Reason for Resource Leaving
		/// </summary>
		public enum LeavingReason
		{
			Resigned = 0 ,
			EndOfContract = 1,
			EarlyRelease= 2
		}
		/// <summary>
		/// Table Type for Audit Trail
		/// </summary>
		public enum AuditTrailTableType
		{
			CrqfData = 0 ,
			ResourceData = 1
		}
		/// <summary>
		/// show flag 
		/// </summary>
		public enum ShowFlag
		{
			HIDDEN= 0 ,
			SHOW = 1
		}
		/// <summary>
		/// Resource Type
		/// </summary>
		public enum ResourceType
		{
			BODYSHOP = 0 ,
			PROJECT = 1
		}
		/// <summary>
		/// Search Type
		/// </summary>
		public enum SearchType
		{
			STARTSWITH	= 0 ,
			ENDSWITH	= 1,
			CONTAINS	= 2,
			EQUALS		= 3
		}
		/// <summary>
		/// Supervisor Type
		/// </summary>
		public enum SupervisorType
		{
			Supervisor  = 0 ,
			ProjectManager= 1
		}
		/// <summary>
		/// ShowCloseBtn Type
		/// </summary>
		public enum ShowCloseBtn
		{
			Show  = 0 ,
			Hidden= 1
		}
		/// <summary>
		/// Report Type
		/// </summary>
		public enum ReportType
		{
			ActualReport = 0 ,
			FlashReport  = 1 ,

		}

		/// <summary>
		/// IsPublish Type
		/// </summary>
		public enum IsPublish
		{
			Publish = 0 ,
			NotPublish  = 1 ,
			Deleted = 2 
		}
		/// <summary>
		/// StaffStatus Type
		/// </summary>
		public enum StaffStatus
		{
			Active = 0 ,
			NonActive  = 1 
		}

		/// <summary>
		/// Category for ResourceManagement  in TMgmtType Table Dictionary
		/// </summary>
		public enum ManagementCategory
		{
			Month = 0,
			Resource = 1
		}

		/// <summary>
		/// Type for ReportResource  in TMgmtType Table Dictionary
		/// </summary>
		public enum ReportResource
		{
			InitialBase = -100,
			Open		= 0,
			Terminate	= 1,
			NewHire		= 2,
			Close		= 3,
			Adjust		= 4
		}

		/// <summary>
		/// Type for the birth of Resources
		/// </summary>
		public enum BirthType
		{
			NewHire		= 0,
			Transfer	= 1
		}

		/// <summary>
		/// Delegation Status  
		/// </summary>
		public enum ActiveExpiredStatus 
		{
			Active		= 0,
			Expired		= 1,
			Cancelled	= 2
		}
		/// <summary>
		/// Login Status  
		/// </summary>
		public enum LoginStatus 
		{
			Invalid		= -1,
			Success		= 0,
			False		= 1
		}
		/// <summary>
		/// Password Expired
		/// </summary>
		public enum PasswordExpired
		{
			Expired		= 0,
			Active		= 1
		}

		/// <summary>
		/// Password Expired
		/// </summary>
		public enum ProjectStatus
		{
			SelectAll		= 0,
			Active			= 1,
			Inactive        =2
		}
		
		/// <summary>
		/// Mail Type   
		/// </summary>
		public enum MailType 
		{
			SendToSupervisor= 1,
			SendToAdmin		= 2,
			RequestorApproved = 3,
			RequestorRejected = 4,
			SendToRequestorByAdmin = 5,
			ToDelegateTo = 6, 
			ToMdDirectorTo	= 7,
			ToDelegateToCancel	=	8,
			ToMdDirectorCancel	=9,
			Maintain		= 10,
			Limit		= 11,
			ReturnCRQF = 12,				//Return a CRQF to request
			ToRequestorDel = 13,			//to requestor that he has been deleted by admin 
			ApproveProExt = 14,				//Approve the Project extension for a Project CRQF
			ToRequestResetPwd = 15,			//Admin reset the password 
			ToRoleChanged = 16,				//send to requestor about role changed
			ToDelegateToExpired = 17,		//send to delegate To about Info Expired
			ToMdDirectExpired = 18			//send to Md director about Info Expired
		}
		/// <summary>
		/// Mail variable    
		/// </summary>
		public enum MailVariable 
		{
			SendToAdminPassword	= 8,
			SendToSupervisorRequestor = 5,
			SendToSupervisorDateTime = 6,
			SendToSupervisorUrl = 7,
			SendToAdminRequestor = 1,
			SendToAdminDateTime = 2,
			SendToAdminUrl = 3,
			RequestorApprovedAdmin = 9,
			RequestorRejectedAdmin = 10,
			
			ToDelegateToDelegateTo = 11,
			ToMdDirectorToMdDirector = 12,
			ToDelegateToCancelDelegateTo = 13,
			ToMdDirectorCancelMdDirector = 14,
			
			MaintainFieldValue = 15,
			MaintainRequestor = 16,
			MaintainUrl = 17,
			
			ToDelegateToStartDate = 18,
			ToDelegateToEndDate = 19,
			ToMdDirectorToStartDate = 20,
			ToMdDirectorToEndDate = 21,
			
			RequestorApprovedPassword = 22,
			
			LimitCrqfCount = 23,
			LimitUnitName = 24,
			LimitLevelName = 25,

			ToSupResubmitRequestName = 26,
			ToSupResubmitAdmin = 27,

			ToRequestorDelAdmin = 28,
			ToRequestorDelDate = 29,

			ToSupDelRequestAdmin = 30,
			ToSupDelRequestDate = 31,
			ToSupDelRequestorName = 32,

			ToRequestResetPwd = 33, //reset password
			ToRequestResetDate = 34,
			ToRequestResetAdmin = 35,

			ToRoleChangedRole = 36 ,
			ToRequestorbyAdminRole = 37,//SendToAdminRequestor
			RequestorApprovedRoleName = 38,//RequestorApproved
		
			ToDelegateToExpiredStartDate = 39,
			ToDelegateToExpiredEndDate = 40,
			ToDelegateToExpiredMdDirect = 41,

			//send to md director for delegation expired
			ToMdDirectExpiredStartDate = 42,
			ToMdDirectExpiredEndDate = 43,
			ToMdDirectExpiredDelegateTo = 44,

			//Mail to the requestor in the event that a CRQF is returned
			Returnee = 45,
			ReturnCRQFNumber = 46,
			Comments = 47,
            ActionDate = 48,                          
			//Mail to inform the requestor in the event that the project extension is fully approved
			ApprovedCRQFNumber = 49,
			OriginalEndDate = 50,
			ApprovedExtendedEndDate =51
		}

		#endregion

		#region Public Static Method

		#region Enum Convert
	
		public static FormUserRight  convertFormUserRight( int iValue,FormUserRight iDefault) 
		{
			if( iValue >= (int)FormUserRight.NEW_RIGHT && iValue <= (int)FormUserRight.SEARCH_RIGHT )
			{
				return  (FormUserRight)iValue;			
			}
			else
			{
				return iDefault;
			}
		}

		/// <summary>
		/// get the form status
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static ApproveStatus convertApproveStatus(  int iValue) 
		{

			if( iValue >= (int)ApproveStatus.Approved && iValue <= (int)ApproveStatus.Locked )
			{
				return  (ApproveStatus)iValue;			
			}
			else
			{
				return ApproveStatus.Pending;
			}			
		}

		/// <summary>
		/// get the fieldType
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static FieldType convertFieldType(  int iValue) 
		{

			if( iValue >= (int)FieldType.INT && iValue <= (int)FieldType.VARCHAR )
			{
				return  (FieldType)iValue;			
			}
			else
			{
				return FieldType.VARCHAR ;
			}			
		}

		/// <summary>
		/// get the form enumTableType
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static enumTableType convertTableType(  int iValue) 
		{

			if( iValue <= (int)enumTableType.AdditionalReason && iValue >= (int)enumTableType.Division )
			{
				return  (enumTableType)iValue;			
			}
			else
			{
				return enumTableType.ContractorRole;
			}			

		}
		/// <summary>
		/// get the UserRole
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static UserRole convertUserRole(  int iValue) 
		{

			if( iValue >= (int)UserRole.UserRole && iValue <= (int)UserRole.SystemAdministrator )
			{
				return  (UserRole)iValue;			
			}
			else
			{
				return UserRole.UserRole;
			}			
		}
		/// <summary>
		/// get the UserSubRole
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static UserSubRole convertUserSubRole(  int iValue) 
		{

			if( iValue >= (int)UserSubRole.Requestor && iValue <= (int)UserSubRole.AtoHead )
			{
				return  (UserSubRole)iValue;			
			}
			else
			{
				return UserSubRole.AtoHead;
			}			
		}

		/// <summary>
		/// convert to TableName
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static TableName convertToTableName(  int iValue) 
		{

			if( iValue >= (int)TableName.TBaseInfo && iValue <= (int)TableName.TCurrencyInfo)
			{
				return  (TableName)iValue;			
			}
			else
			{
				return TableName.TCurrencyInfo;
			}			
		}

		
		/// <summary>
		/// get the form status
		/// </summary>
		/// <param name="iValue"></param>
		/// <param name="iDefault"></param>
		/// <returns></returns>

		public static FormControlStatus  convertFormStatus( int iValue) 
		{
			if( iValue >= (int)FormControlStatus.NEW_STATUS && iValue <= (int)FormControlStatus.CANCEL_STATUS )
			{
				return  (FormControlStatus)iValue;			
			}
			else
			{
				return FormControlStatus.CANCEL_STATUS;
			}
		}

		/// <summary>
		/// Convert to ControlSystem
		/// </summary>
		/// <param name="iValue"></param>
		/// <param name="iDefault"></param>
		/// <returns></returns>

		public static ControlSystem  convertControlSystem( int iValue) 
		{
			if( iValue >= (int)ControlSystem.SERVICE && iValue <= (int)ControlSystem.CONTRACTOR_TYPE )
			{
				return  (ControlSystem)iValue;			
			}
			else
			{
				return ControlSystem.CONTRACTOR_TYPE;
			}
		}

		
		/// <summary>
		/// Convert to AttachmentTrailStatus
		/// </summary>
		/// <param name="iValue"></param>
		/// <param name="iDefault"></param>
		/// <returns></returns>

		public static AttachmentTrailStatus  convertAttachmentTrailStatus( int iValue) 
		{
			if( iValue >= (int)AttachmentTrailStatus.Attachment && iValue <= (int)AttachmentTrailStatus.Trail)
			{
				return  (AttachmentTrailStatus)iValue;			
			}
			else
			{
				return AttachmentTrailStatus.Trail;
			}
		}
		
		/// <summary>
		/// convert to attachment Type
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static AttachmentType  convertAttachmentType( int iValue) 
		{
			if( iValue >= (int)AttachmentType.FUND_BY && iValue <= (int)AttachmentType.SOW_EXTENSION )
			{
				return  (AttachmentType)iValue;			
			}
			else
			{
				return AttachmentType.SOW_EXTENSION ;
			}
		}

		/// <summary>
		/// convert to Delete flag
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static DeleteFlag  convertDeleteFlag( int iValue) 
		{
			if( iValue >= (int)DeleteFlag.EXISTS && iValue <= (int)DeleteFlag.DELETED)
			{
				return  (DeleteFlag)iValue;			
			}
			else
			{
				return DeleteFlag.DELETED ;
			}
		}
		/// <summary>
		/// convert to Role Type
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static RoleType  convertRoleType( int iValue) 
		{
			if( iValue >= (int)RoleType.Supervisor && iValue <= (int)RoleType.Supervisor)
			{
				return  (RoleType)iValue;			
			}
			else
			{
				return RoleType.Supervisor;
			}
		}
		/// <summary>
		/// convert to CrqfStatus
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static CrqfStatus convertCrqfStatus( int iValue) 
		{
			if( iValue >= (int)CrqfStatus.Draft && iValue <= (int)CrqfStatus.Archive)
			{
				return  (CrqfStatus)iValue;			
			}
			else
			{
				return CrqfStatus.Archive;
			}
		}
		/// <summary>
		/// convert to ContractorType
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static ContractorType convertContractorType( int iValue) 
		{
			if( iValue >= (int)ContractorType.R && iValue <= (int)ContractorType.S)
			{
				return  (ContractorType)iValue;			
			}
			else
			{
				return ContractorType.S;
			}
		}
		/// <summary>
		/// convert to Resource Type
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static ResourceType convertResourceType( int iValue) 
		{
			if( iValue >= (int)ResourceType.BODYSHOP && iValue <= (int)ResourceType.PROJECT)
			{
				return  (ResourceType)iValue;			
			}
			else
			{
				return ResourceType.BODYSHOP;
			}
		}

		/// <summary>
		/// convert to Search Type
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static SearchType convertSearchType( int iValue) 
		{
			if( iValue >= (int)SearchType.STARTSWITH && iValue <= (int)SearchType.EQUALS )
			{
				return  (SearchType)iValue;			
			}
			else
			{
				return SearchType.STARTSWITH;
			}
		}

		/// <summary>
		/// convert to showCloseBtn
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static ShowCloseBtn convertShowCloseBtn( int iValue) 
		{
			if( iValue >= (int)ShowCloseBtn.Show && iValue <= (int)ShowCloseBtn.Hidden )
			{
				return  (ShowCloseBtn)iValue;			
			}
			else
			{
				return ShowCloseBtn.Show;
			}
		}

		/// <summary>
		/// convert to ResourceStatus
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static ResourceStatus convertResourceStatus( int iValue) 
		{
			if( iValue >= (int)ResourceStatus.OVERLAPPING && iValue <= (int)ResourceStatus.RENEW )
			{
				return  (ResourceStatus)iValue;			
			}
			else
			{
				return ResourceStatus.OVERLAPPING;
			}
		}

		/// <summary>
		/// convert to IsPublish
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static IsPublish convertIsPublish( int iValue) 
		{
			if( iValue >= (int)IsPublish.Publish && iValue <= (int)IsPublish.NotPublish)
			{
				return  (IsPublish)iValue;			
			}
			else
			{
				return IsPublish.Publish;
			}
		}

		/// <summary>
		/// convert to LeavingReason
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static LeavingReason convertLeavingReason( int iValue) 
		{
			if( iValue >= (int)LeavingReason.Resigned && iValue <= (int)LeavingReason.EarlyRelease )
			{
				return  (LeavingReason)iValue;			
			}
			else
			{
				return LeavingReason.Resigned;
			}
		} 
		/// <summary>
		/// convert to Type Of Service
		/// </summary>
		/// <param name="iValue"></param>
		/// <returns></returns>
		public static TypeOfService convertTypeOfService( int iValue) 
		{
			if( iValue >= (int)TypeOfService.BodyShop && iValue <= (int)TypeOfService.FixedPrice )
			{
				return  (TypeOfService)iValue;			
			}
			else
			{
				return TypeOfService.FixedPrice;
			}
		} 
		#endregion

		#region Method for DropDownList, RadioButtonList

		/// <summary>
		/// Get distinct data from columns of DataSet collection and then bind it to DropDownList,
		/// with head "--Select All--"
		/// </summary>
		/// <param name="dataTextField"></param>
		/// <param name="dataValueField"></param>
		/// <param name="ddl"></param>
		/// <param name="dsCollection"></param>
		public static void bindDistinct( string dataTextField, string dataValueField, DropDownList ddl, params DataSet[] dsCollection  )
		{	
			bindDistinct( dataTextField, dataValueField, ddl, false, dsCollection );
		}

		/// <summary>
		/// Get distinct data from columns of DataSet collection and then bind it to DropDownList,
		/// with head "--Select All--"
		/// </summary>
		/// <param name="dataTextField"></param>
		/// <param name="dataValueField"></param>
		/// <param name="ddl"></param>
		/// <param name="dsCollection"></param>
		public static void bindDistinct( string dataTextField, string dataValueField, DropDownList ddl, bool nonselective, params DataSet[] dsCollection  )
		{			
			DataSet distinctDs = DataSetHelper.getDistinctFromColumn( dataTextField, dataValueField, dsCollection );
			bindWithHeadSelectAll( dataTextField, dataValueField, ddl, distinctDs, nonselective );
		}

		/// <summary>
		/// Bind data to DropDownList with head "--Select All--"
		/// </summary>
		/// <param name="dataTextField"></param>
		/// <param name="dataValueField"></param>
		/// <param name="ddl"></param>
		/// <param name="ds"></param>
		public static void bindWithHeadSelectAll( string dataTextField, string dataValueField, DropDownList ddl, DataSet ds  )
		{
			bindWithHeadSelectAll( dataTextField, dataValueField, ddl, ds, false );
		}		

		/// <summary>
		/// Bind data to DropDownList with head "--Select All--"
		/// </summary>
		/// <param name="dataTextField"></param>
		/// <param name="dataValueField"></param>
		/// <param name="ddl"></param>
		/// <param name="ds"></param>
		public static void bindWithHeadContains( string dataTextField, string dataValueField, DropDownList ddl, DataSet ds  )
		{
			bindWithHeadSelectAll( dataTextField, dataValueField, ddl, ds, false );
			SetSearchDllToContain(ddl);
		}	

		/// <summary>
		/// Set the Dll to Contain option
		/// </summary>
		/// <param name="ddl"></param>
		private static void SetSearchDllToContain(DropDownList ddl)
		{
			for(int i = 0 ; i<ddl.Items.Count ; i++)
			{
				if(ddl.Items[i].Text.ToUpper() == FormHelp.SearchType.CONTAINS.ToString() )
				{
					ddl.Items[i].Selected = true;
				}
			}		
		}


		/// <summary>
		/// Bind DropDownList by data from table TBaseInfo with head "--Select All--"
		/// </summary>
		/// <param name="ds"></param>
		/// <param name="ctrl"></param>
		public static void bindWithHeadSelectAll( DataSet ds, DropDownList ddl )
		{	
			bindWithHeadSelectAll( BASE_TEXT_VALUE, BASE_FIELD_VALUE, ddl, ds );
		}

		/// <summary>
		/// Bind data to DropDownList with head "--Select All--"
		/// </summary>
		/// <param name="dataTextField"></param>
		/// <param name="dataValueField"></param>
		/// <param name="ddl"></param>
		/// <param name="ds"></param>
		public static void bindWithHeadSelectAll( string dataTextField, string dataValueField, DropDownList ddl, DataSet ds, bool nonselective, bool isDesc )
		{	
			ListControlHelp.setCtrlValuesByDs( ds, ddl, dataTextField, dataValueField, nonselective, isDesc );
			if ( ddl != null && ddl.Items.Count > 0 )
			{
				ddl.Items[ 0 ].Text = HEAD_SELECT_ALL;
			}
		}	

		/// <summary>
		/// Bind data to DropDownList with head "--Select All--"
		/// </summary>
		/// <param name="dataTextField"></param>
		/// <param name="dataValueField"></param>
		/// <param name="ddl"></param>
		/// <param name="ds"></param>
		public static void bindWithHeadSelectAll( string dataTextField, string dataValueField, DropDownList ddl, DataSet ds, bool nonselective )
		{	
			bindWithHeadSelectAll( dataTextField, dataValueField, ddl, ds, nonselective, false );
		}	

		/// <summary>
		/// Add to DropDownList with head "--Select All--"
		/// </summary>
		/// <param name="dataTextField"></param>
		/// <param name="dataValueField"></param>
		/// <param name="ddl"></param>
		/// <param name="ds"></param>
		public static void addHeadSelectAll( DropDownList ddl )
		{	
			ListItem item = new ListItem( HEAD_SELECT_ALL, string.Empty );
			ddl.Items.Insert( 0, item );
		}		

		/// <summary>
		/// Bind DropDownList by data from table TBaseInfo
		/// </summary>
		/// <param name="ds"></param>
		/// <param name="ctrl"></param>
		public static void bindCtrlByBaseInfo(  DataSet ds, DropDownList ddl )
		{	
			ListControlHelp.setCtrlValuesByDs( ds, ddl, BASE_TEXT_VALUE, BASE_FIELD_VALUE );
		}

		/// <summary>
		/// Bind DropDownList by data from table TControlSystem
		/// </summary>
		/// <param name="ds"></param>
		/// <param name="ctrl"></param>
		public static void bindCtrlByControlInfo(  DataSet ds, DropDownList ddl )
		{	
			string dataTextField = "ControlValue";
			string dataValueField = "ControlKey";
			ListControlHelp.setCtrlValuesByDs( ds, ddl, dataTextField, dataValueField );
		}

		

		/// <summary>
		/// Get text of selected item for DropDownList
		/// </summary>
		/// <param name="ddl"></param>
		/// <returns></returns>
		public static string getSelectedItemText( DropDownList ddl )
		{
			return ddl.SelectedIndex <= 0
				? string.Empty : ddl.SelectedItem.Text;		 
		}

		/// <summary>
		/// Get text of selected item for RadioButtonList
		/// </summary>
		/// <param name="rbl"></param>
		/// <returns></returns>
		public static string getSelectedItemText( RadioButtonList rbl )
		{
			return rbl.SelectedIndex < 0
				? string.Empty : rbl.SelectedItem.Text;		 
		}

		#endregion	

		#region Page Helper


		public static void alert(object message)
		{
			string js=@"<Script language='JavaScript'>
                    alert('{0}');  
                  </Script>";
			HttpContext.Current.Response.Write(string.Format(js,message.ToString()));
		}

		public static void confirmMsgbox(object message)
		{   
			string js = @"<Script language='JavaScript'>
			 if(!alert('"+ message +"')) return false;</Script>";
			HttpContext.Current.Response.Write(string.Format(js,message.ToString()));
		}

		public static void openClintWindow(Page  clsPage ,string sUrl,string sName)
		{
			openClintWindow(clsPage, sUrl, sName, "400", "300");
		}
		
		
		public static void openClintWindow(Page clsPage,string sUrl,string sName,string sHeight,string sWidth)
		{
			//Script for popup window
			
			string Script = "";
			Script += "<script language=JavaScript id='PopupWindow'>\n";
			Script += "var confirmWin = null; \n";
			Script += "confirmWin = window.open('"+sUrl+"','"+sName +"', 'width="+ sWidth+" ,height=" + sHeight+ ",left=20,top=20,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes'); \n";

			Script += "if((confirmWin != null) && (confirmWin.opener==null)){\n";
			Script += "  confirmWin.opener = self; \n";
			Script += "}\n";
			Script += "</script>";

			//Check whether they are already registered
			if(!clsPage.IsStartupScriptRegistered("PopupWindow"))
			{
				//Register the script
				clsPage.RegisterStartupScript("PopupWindow",Script);
			}
		}


		public static void openClintModalWindow(Page clsPage ,string sUrl,string sName)
		{
			string sLinkScript="";
			sLinkScript += "<SCRIPT LANGUAGE=\"JavaScript\">";
			sLinkScript += "window.showModalDialog(\"" + sUrl + "\",";			
			sLinkScript += "\"dialogHeight:600px;";
			sLinkScript += "dialogWidth:800px;";
			sLinkScript += "center:yes;";
			sLinkScript += "resizable:yes;";
			sLinkScript += "scroll:yes\");";
			sLinkScript += "</SCRIPT>";
			clsPage.RegisterStartupScript("", sLinkScript);		
		}	

		public static void changePageLocation(Page clsPage,string  sUrl)
		{
			string sLinkScript="";
			sLinkScript += "<SCRIPT LANGUAGE='JavaScript'>";
			sLinkScript += "document.location.href='" + sUrl + "';";
			sLinkScript += "</SCRIPT>";
			clsPage.RegisterStartupScript("A", sLinkScript);			
		}

		public static void ClosePageLocation(Page clsPage,string sUrl)
		{
			string sLinkScript="";

			sLinkScript += "<SCRIPT LANGUAGE='JavaScript'>";
			sLinkScript += "window.close();";
			sLinkScript += "</SCRIPT>";
			clsPage.RegisterStartupScript("A", sLinkScript);		
		}
		public static void CloseRefreshPage(Page clsPage)
		{
			string sLinkScript="";

			sLinkScript += "<SCRIPT LANGUAGE='JavaScript'>";
			sLinkScript +="window.opener.refreshForm();";
			sLinkScript += "window.close();";		
			sLinkScript += "</SCRIPT>";
			clsPage.RegisterStartupScript("B", sLinkScript);		
		}

		#endregion
		
		#region Format Helper

		/// <summary>
		/// Format to Dollar
		/// </summary>
		/// <param name="obj"></param>
		/// <returns></returns>
		public static string formatDollar( object dec )
		{
			string result = string.Empty;

			if ( dec != null && dec != DBNull.Value )
			{
				result = ( ( decimal )dec ).ToString( _DollarFormat );
			}

			return result;
		}

		/// <summary>
		/// Format to Dollar
		/// </summary>
		/// <param name="dec"></param>
		/// <returns></returns>
		public static string formatDollar( decimal dec )
		{
			return dec.ToString( _DollarFormat );
		}

		/// <summary>
		/// Format to standard Date
		/// </summary>
		/// <param name="dt"></param>
		/// <returns></returns>
		public static string formatDate( DateTime dt )
		{
			return dt.ToString( _DateFormat );
		}
		
		/// <summary>
		/// Format to long Date
		/// </summary>
		/// <param name="dt"></param>
		/// <returns></returns>
		public static string formatLongDate( DateTime dt )
		{
			return dt.ToString( DateLongFormat );
		}

		/// <summary>
		/// Format to standard Date
		/// </summary>
		/// <param name="dt"></param>
		/// <returns></returns>
		public static string formatDate( object dt )
		{
			string result = string.Empty;

			if ( dt != null && dt != DBNull.Value )
			{				
				result = ( ( DateTime )dt ).ToString( _DateFormat );
			}

			return result;
		}

		/// <summary>
		/// Format the string date to the standard format string 
		/// </summary>
		/// <param name="dt"></param>
		/// <param name="dateFormat"></param>
		/// <returns></returns>
		public static string FormatDate( string dt , string dateFormat){

			string result = string.Empty;

			if ( dt != null && dt.Length > 0 )
			{				
				result =  Convert.ToDateTime(dt ).ToString( dateFormat );
			}

			return result;		
		}


		#endregion		

		#region  add warning message for image button in datagrid

		/// <summary>
		/// add warning message for image button in datagrid
		/// </summary>
		/// <param name="warningMsg"></param>
		/// <param name="dg"></param>
		/// <param name="imgBtnName"></param>
		public static void addWarningMsg( string warningMsg , 
			DataGrid dg, string  imgBtnName)
		{
	
			foreach(DataGridItem dgi in dg.Items)
			{
				ImageButton imgbtn =((ImageButton)dgi.FindControl( imgBtnName ));		
				imgbtn.Attributes.Add("onclick","return confirm('"+warningMsg+"');");
			}

		}
		#endregion
		
		#region Password Helper

		
		/// <summary>
		/// create password
		/// </summary>
		/// <param name="orignPwd"></param>
		/// <returns></returns>
		public static string  createPassword( ref string orignPwd)
		{
			string randomLetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
			string ranLetts = MakePassword(randomLetters, 11); 			

			System.Random random	= new Random();
			double dbNumber			= random.NextDouble() * 10000000000;
			orignPwd				= dbNumber.ToString().Substring(0,10);
			char[] oriPwdChar       = orignPwd.ToCharArray();			

			//Get the random integer less than 10
			int ranRet = random.Next(10);
			if(ranRet <  1)
			{
				ranRet = 5;
			}
			//Char 
			for(int i = 0; i < ranRet ; i++)
			{				
				oriPwdChar[i] = Convert.ToChar(ranLetts.Substring(i,1));			
			}
			//Set the Random Passwords
			orignPwd = "";
			for(int i = 0 ; i < oriPwdChar.Length ; i++ )
			{
				orignPwd = orignPwd + oriPwdChar[i].ToString();			
			}
			//orignPwd = oriPwdChar.GetLowerBound
			return FormsAuthentication.HashPasswordForStoringInConfigFile( orignPwd, "MD5") ; 			
		}

		public static string MakePassword(string pwdchars, int pwdlen)
		{ 
			string tmpstr = ""; 
			int iRandNum; 
			Random rnd = new Random(); 
			for(int i=0;i<pwdlen;i++)
			{ 
				iRandNum = rnd.Next(pwdchars.Length); 
				tmpstr += pwdchars[iRandNum]; 
			} 
			return tmpstr; 
		} 

		#endregion

		/// <summary>
		/// Check if is expired - Only compare Date and ignore Time
		/// </summary>
		/// <param name="today"></param>
		/// <param name="endDate"></param>
		/// <returns></returns>
		public static bool CheckExpired( DateTime today, DateTime endDate )
		{
			const string FORMAT = "yyyy-MM-dd";
			today				= DateTime.Parse( today.ToString( FORMAT ) );
			endDate				= DateTime.Parse( endDate.ToString( FORMAT ) );
			return endDate.CompareTo( today ) < 0;
		}

		/// <summary>
		/// Format condition for search
		/// </summary>
		/// <param name="searchType"></param>
		/// <param name="fieldName"></param>
		/// <param name="parmName"></param>
		/// <returns></returns>
		public static string FormatSearchCondition( SearchType searchType, string fieldName, string parmName )
		{
			string condition = string.Empty;

			if ( !parmName.StartsWith( "@" ) )
			{
				parmName = "@" + parmName;
			}

			switch ( searchType )
			{
				case FormHelp.SearchType.CONTAINS :
					condition = string.Format(" {0} LIKE ( '%' + {1} + '%' ) ", fieldName, parmName )  ;
					break;

				case FormHelp.SearchType.STARTSWITH :
					condition = string.Format(" {0} LIKE ( {1} + '%' ) ", fieldName, parmName )  ;
					break;

				case FormHelp.SearchType.ENDSWITH :
					condition = string.Format(" {0} LIKE  ( '%' + {1} ) ", fieldName, parmName )  ;
					break;

				default :
					condition = string.Format(" {0} = {1} ", fieldName, parmName )  ;
					break;
			}

			return condition;
		}

		#endregion
	}
}